package com.c.ctgproject.wiget.dialog

import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseDialogFragment
import com.c.ctgproject.base.BaseDialogFragmentBottom
import com.c.ctgproject.utils.MyLog
import com.c.ctgproject.utils.handlerHttpResult
import com.c.ctgproject.utils.showToast
import kotlinx.android.synthetic.main.item_file_manager_dialog.*

class FileManagerMoreDialog(private val selectList: List<String>, private val listener: FileManagerMoreCallback) : BaseDialogFragmentBottom() {
    private val mViewModel by lazy { ViewModelProvider(this)[FileManagerMoreViewModel::class.java] }

    //1:邮寄 2:车主自取 3:业务领取
    private var currentSelect = "0"
    override fun viewIsCreated(view: View, savedInstanceState: Bundle?) {
        dialog?.setCanceledOnTouchOutside(true)
        //回收录入
        huishouluru.setOnClickListener {
            mViewModel.batchGiveRecycleProof(selectList)
        }
        //注销办理
        zhuxiaobanli.setOnClickListener {
            mViewModel.batchGiveCancellationProof(selectList)
        }
        //手续发放
        shouxufafang.setOnClickListener {
            listener.onBatchGiveProcedure(selectList)
        }

        mViewModel.error.observe(this,  {
            MyLog.d("错误:$it")
            showToast(it)
        })

        mViewModel.result.observe(this,  {
            MyLog.d("商品列表:$it")
            requireActivity().handlerHttpResult(it){
                listener.onFinish()
            }
        })


    }

    override fun getLayout() = R.layout.item_file_manager_dialog
    interface FileManagerMoreCallback {
        fun onFinish()
        fun onBatchGiveProcedure( selectList: List<String>)
    }
}